package com.kamistoat.ruoyi.ruoyimodulessystem.service.impl;

import com.kamistoat.ruoyi.ruoyiapisystem.domain.SysOperLog;
import com.kamistoat.ruoyi.ruoyicommoncore.utils.StringUtils;
import com.kamistoat.ruoyi.ruoyicommoncore.utils.page.Query;
import com.kamistoat.ruoyi.ruoyimodulessystem.service.SysOperLogService;
import com.kamistoat.ruoyi.ruoyimodulessystem.dao.SysOperLogDao;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kamistoat.ruoyi.ruoyicommoncore.utils.page.PageUtils;
import com.kamistoat.ruoyi.ruoyiapisystem.entity.SysOperLogEntity;


@Service("sysOperLogService")
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogDao, SysOperLogEntity> implements SysOperLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SysOperLogEntity> page = this.page(
                new Query<SysOperLogEntity>().getPage(params),
                new QueryWrapper<SysOperLogEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SysOperLogEntity> selectOperLogList(SysOperLog operLog) {
        QueryWrapper<SysOperLogEntity> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotNull(operLog.getTitle())) {
            queryWrapper.like("title", operLog.getTitle());
        }
        if (StringUtils.isNotNull(operLog.getBusinessType())) {
            queryWrapper.eq("business_type", operLog.getBusinessType());
        }
        if (StringUtils.isNotNull(operLog.getBusinessTypes())) {
            queryWrapper.in("business_type", operLog.getBusinessTypes());
        }
        if (StringUtils.isNotNull(operLog.getStatus())) {
            queryWrapper.eq("status", operLog.getStatus());
        }
        if (StringUtils.isNotNull(operLog.getOperName())) {
            queryWrapper.like("oper_name", operLog.getOperName());
        }
        if (StringUtils.isNotEmpty((String) operLog.getParams().get("beginTime"))) {
            queryWrapper.ge("create_time", operLog.getParams().get("beginTime"));
        }
        if (StringUtils.isNotEmpty((String) operLog.getParams().get("endTime"))) {
            queryWrapper.le("create_time", operLog.getParams().get("endTime"));
        }
        return this.list(queryWrapper);
    }

    @Override
    public void cleanOperLog() {
        this.getBaseMapper().cleanOperLog();
    }

}